package com.lzj.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lzj.myapplication.bean.LunBo;
import com.lzj.myapplication.http.HttpCallback;
import com.lzj.myapplication.http.HttpHelper;
import com.lzj.myapplication.widget.MyView;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements MyView.MyInterface,View.OnClickListener{


//    private String url = HttpUtil.GET_SERIAL_ROTATE;

    private String url  = "http://app.mabaotoutiao.com/mommy/pic/carouselFigure.do";
    private TextView tv;
    private HashMap<String , Object> params = new HashMap<>();
    @BindView(R.id.text)
    TextView textView;
    @BindView(R.id.text1)
    TextView textView1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        textView1.setOnClickListener(this);
        //测试提交数据
        textView.setOnClickListener(this);

        tv =   (TextView)findViewById(R.id.tv);
        MyView mv =   (MyView)findViewById(R.id.mv);
        mv.setMyInterFace(this);

    }

    public void toast(String string){
        Toast.makeText(this, string , Toast.LENGTH_SHORT).show();
    }

    @Override
    public void getValue(String value) {
        tv.setText(value);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.text:
                HttpHelper.getInstance().get(url, params, new HttpCallback<LunBo>() {
                    @Override
                    public void onSuccess(LunBo lunbo) {
                        Log.i("lzj","size  "+lunbo.getData().getList().size());
                        Log.i("lzj","link  "+lunbo.getData().getList().get(0).getPic_url());
                        toast("请求成功"+lunbo.getData().getList().get(0).getPic_url());
                    }

                    @Override
                    public void onFailed(String string) {
                        toast("请求失败");
                    }
                });
                break;
            case R.id.text1:
                Intent intent = new Intent(this,ImageActivity.class);
                startActivity(intent);
                break;
        }
    }
}
